function spliceUrl(url) {
  return window.RPConfig.modeler + 'app/rest/' + url
}

// 获取流程分类的所有节点
export function getModelTypeList() {
  return $http.post(spliceUrl('procType/queryList'), {})
}

// 保存新增的流程分类
export function addModelType(modelType) {
  return $http.post(spliceUrl('procType/save'), modelType)
}

// 更新流程分类
export function updateModelType(modelType) {
  return $http.post(spliceUrl('procType/update'), modelType)
}

// 删除流程分类
export function deleteModelType(procTypeId) {
  return $http.post(spliceUrl(`procType/delete/${procTypeId}`))
}

// 获取流程分类的流程列表
export function queryModelList(searchInfo) {
  return $http.post(spliceUrl('procType/models/queryPageList'), searchInfo)
}

// 新建流程
export function createModel(procTypeId, modelInfo) {
  return $http.post(spliceUrl(`crmodel/createModel/${procTypeId}`), modelInfo)
}

// 更新流程
export function updateModel(modelInfo) {
  return $http.post(spliceUrl(`crmodel/updateModel/${modelInfo.id}`), modelInfo)
}

// 删除流程
export function deleteModel({ procTypeId, id: modelId }) {
  return $http.post(spliceUrl(`crmodel/deleteModel/${procTypeId}/${modelId}`))
}

// 发布流程
export function publishModel(modelInfo) {
  return $http.post(spliceUrl(`appDefinitionPublish/publish`), modelInfo)
}

// 导出流程数据
export function exportModel(modelId) {
  return $http.get(spliceUrl(`models/${modelId}/bpmn20?version=${Date.now()}`), null, null, { responseType: 'blob' })
}

// 复制流程
export function copyModel(procTypeId, modelInfo) {
  return $http.post(spliceUrl(`crmodel/clone/${procTypeId}/${modelInfo.id}`), modelInfo)
}

// 导入流程
export function importModel(procTypeId, modelInfo, file) {
  const formData = new FormData()
  formData.append('file', file)
  for (let key in modelInfo) {
    formData.append(key, modelInfo[key])
  }

  return $http.post(spliceUrl(`crmodel/import-process-model/${procTypeId}`), formData, null, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
